<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="config.ApplicationConfig" %>
<%@ page import="server.RecordServer" %>
<%@ page import="java.util.LinkedList" %>
<%@ page import="server.SettingServer" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="server.FileServer" %>
<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="util.Decode" %><%--
  Created by IntelliJ IDEA.
  User: tum0r
  Date: 2019-04-17
  Time: 14:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Accepted动态</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/page.css">
    <link rel="stylesheet" href="css/index.css">
</head>
<body>

<%
    LinkedHashMap<String, String> pageConfig = ApplicationConfig.readConfig("page.json");
    request.setCharacterEncoding(pageConfig.get("encode"));
    response.setCharacterEncoding(pageConfig.get("encode"));
    response.addHeader("refresh", "10;URL=dynamic_accepted.jsp");
    SettingServer settingServer = new SettingServer();
    settingServer.open();
%>

<nav class="navbar navbar-inverse head" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target="#navbar">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <%
                JSONObject logo = settingServer.readSettingObject("logo");
                if (logo.getString("logo").equals("")) {
            %>
            <img class="navbar-brand" src="image/logo.png">
            <%
            } else {
                FileServer fileServer = new FileServer();
                fileServer.open();
            %>
            <img class="navbar-brand" src="<%=fileServer.getImage(logo.getString("logo"))%>">
            <%
                    fileServer.close();
                }
            %>
            <a class="navbar-brand" href="#"><%=logo.getString("name")%>
            </a>
        </div>
    </div>
</nav>

<table class="table table-striped word_break head">
    <tr>
        <td class="text-center"><b>序号</b></td>
        <td class="text-center"><b>提交者</b></td>
        <td class="text-center"><b>题目</b></td>
        <td class="text-center"><b>语言</b></td>
        <td class="text-center"><b>时间</b></td>
        <td class="text-center"><b>内存</b></td>
        <td class="text-center"><b>提交时间</b></td>
    </tr>
    <%
        RecordServer recordServer = new RecordServer();
        recordServer.open();
        LinkedList<LinkedHashMap<String, Object>> result = recordServer.getAcceptedRecord();
        recordServer.close();
        LinkedHashMap<String, Object> item;
        for (int i = result.size() - 1; i >= 0; i--) {
            item = result.get(i);
    %>
    <tr>
        <td class="text-center"><%=(i + 1)%>
        </td>
        <td class="text-center"><%=item.get("username")%>
        </td>
        <td class="text-center"><%=item.get("title")%>
        </td>
        <td class="text-center"><%=item.get("language")%>
        </td>
        <td class="text-center"><%=item.get("time")%> ms
        </td>
        <td class="text-center"><%=item.get("memory")%> kb
        </td>
        <td class="text-center"><%=item.get("submit_time")%>
        </td>
    </tr>
    <%
        }
    %>
</table>
<br>
<%
    JSONArray foot = settingServer.readSettingArray("foot");
    JSONObject foot0 = foot.getJSONObject(0);
    JSONObject foot1 = foot.getJSONObject(1);
    JSONObject foot2 = foot.getJSONObject(2);
    Decode decode = new Decode();
%>
<div class="foot_dynamic_accepted">
    <row>
        <div class="col-xs-4 col-sm-4">
            <br>
            <div class="foot_item_title">
                <p><%=decode.utf8Decode(foot0.getString("title"))%>
                </p>
            </div>
            <hr class="foot_split">
            <div class="foot_item">
                <p><%=decode.utf8Decode(foot0.getString("line0"))%>
                </p>
                <p><%=decode.utf8Decode(foot0.getString("line1"))%>
                </p>
                <p><%=decode.utf8Decode(foot0.getString("line2"))%>
                </p>
            </div>
        </div>
        <div class="col-xs-4 col-sm-4">
            <br>
            <div class="foot_item_title">
                <p><%=decode.utf8Decode(foot1.getString("title"))%>
                </p>
            </div>
            <hr class="foot_split">
            <div class="foot_item">
                <p><%=decode.utf8Decode(foot1.getString("line0"))%>
                </p>
                <p><%=decode.utf8Decode(foot1.getString("line1"))%>
                </p>
                <p><%=decode.utf8Decode(foot1.getString("line2"))%>
                </p>
            </div>
        </div>
        <div class="col-xs-4 col-sm-4">
            <br>
            <div class="foot_item_title">
                <p><%=decode.utf8Decode(foot2.getString("title"))%>
                </p>
            </div>
            <hr class="foot_split">
            <div class="foot_item">
                <p><%=decode.utf8Decode(foot2.getString("line0"))%>
                </p>
                <p><%=decode.utf8Decode(foot2.getString("line1"))%>
                </p>
                <p><%=decode.utf8Decode(foot2.getString("line2"))%>
                </p>
            </div>
        </div>
    </row>
</div>
<%
    settingServer.close();
%>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/page.js"></script>
</html>
